package com.eshop.product.controller;

import com.eshop.product.service.CategoryService;
import com.eshop.product.model.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName CategoryController
 * @Description
 * @Author 47980
 * @Date 2020/5/17 16:18
 * @Version V_1.0
 **/
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/add")
    public String add (Category category, String operationType) {
        try {
            categoryService.add(category, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";

    }

    @GetMapping("/update")
    public String update (Category category, String operationType) {
        try {
            categoryService.update(category, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/delete")
    public String delete (Long id, String operationType) {
        try {
            categoryService.delete(id, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/findById")
    public Category findById (Long id) {
        return categoryService.findById(id);
    }
}
